package com.example.weiwing.util;

public class TimeUtils {
    /**
     * 功能描述 秒转时分秒
     *
     * @param sumSecond 总秒数
     * @return java.lang.String 返回 “ 01:01:01 ” 格式的时间
     * @author qinda
     * @date 2020/10/29
     */
    public static String sumSecondToTime(Long sumSecond) {
        sumSecond /= 1000;
        if (sumSecond <= 0) {
            return "00:00:00";
        }
        Long h = sumSecond / 3600;
        Long m = (sumSecond - h * 3600) / 60;
        Long s = sumSecond - h * 3600 - m * 60;
        String time = "%02d:%02d:%02d";
        time = String.format(time, h, m, s);
        return time;
    }

    public static String sumSecondToMSTime(Long sumSecond) {
        if (sumSecond <= 0) {
            return "00:00:00.000";
        }
        Long ms = sumSecond % 1000;
        sumSecond /= 1000;
        Long h = sumSecond / 3600;
        Long m = (sumSecond - h * 3600) / 60;
        Long s = sumSecond - h * 3600 - m * 60;
        String time = "%02d:%02d:%02d.03d%";
        time = String.format(time, h, m, s, ms);
        return time;
    }

}
